#include <iostream>
#include <set>
#include <vector>
#include <iterator>
#include <vector>
#include <thread>
#include <sw/redis++/redis++.h>

using namespace std;
using namespace sw::redis;

void test(Redis &redis)
{
    cout << "sadd and smembers" << endl;

    redis.flushall();

    redis.sadd("key", "000");

    redis.sadd("key", {"111", "222", "333", "444"});

    std::vector<string> v({"555", "666", "777"});
    redis.sadd("key", v.begin(), v.end());

    set<string> set_;
    auto it = std::inserter(set_, set_.end());
    redis.smembers("key", it);

    for (auto item : set_)
    {
        cout << "val: " << item << endl;
    }
}

void test1(Redis &redis)
{
    cout << "spop " << endl;

    redis.flushall();

    redis.sadd("key", {"111", "222", "333", "444", "555", "666"});

    vector<string> result;
    auto it = std::back_inserter(result);
    redis.spop("key", 3, it);

    cout << result[0] << " : " << result[1] << " : " << result[2] << endl;
}

void test2(Redis &redis)
{
    cout << "srandmember " << endl;

    redis.flushall();

    redis.sadd("key", {"111", "222", "333", "444", "555", "666"});

    vector<string> result;
    auto it = std::back_inserter(result);
    redis.srandmember("key", 3, it);

    cout << result[0] << " : " << result[1] << " : " << result[2] << endl;
}

void test3(Redis &redis)
{
    cout << "sinterstore " << endl;

    redis.flushall();

    redis.sadd("key1", {"111", "222", "333", "444"});

    redis.sadd("key2", {"333", "444", "555", "666"});

    auto count = redis.sinterstore("key3", {"key1", "key2"});

    cout << "interstore: " << count << endl;

    vector<string> result;
    auto it = std::back_inserter(result);
    redis.smembers("key3", it);

    for(auto item : result)
    {
        cout << "val: " << item << endl;
    }
}
void test4(Redis& redis)
{
    cout << "" << endl;
}

int main()
{
    Redis redis("tcp://127.0.0.1:6379");
    // test(redis);
    // test1(redis);
    // test2(redis);
    // test3(redis);
    test4(redis);
    return 0;
}